import LevelInitBase from "../LevelCommon/LevelInitBase";
import LevelControl6 from "../LevelControl/LevelControl6";
import RoomControl from "../LevelCommon/RoomControl";
import { utils } from "../../utils/CommonUtil";
import RotateObj from "../Prefabs/InteractivObj/Common/RotateObj";
import MoveObj from "../Prefabs/InteractivObj/Common/MoveObj";
import FocusParentObj from "../Prefabs/InteractivObj/Common/FocusParentObj";
import GamePropObj from "../Prefabs/InteractivObj/Common/GamePropObj";
import CallToLevel from "../Prefabs/CallToLevel";
import Gate from "../Prefabs/InteractivObj/Gate";
import EnumData from "../../Enum/EnumData";
import PasswordBox from "../Prefabs/InteractivObj/PasswordBox/PasswordBox";
import PasswordKey from "../Prefabs/InteractivObj/Password/PasswordKey";
import PasswordBoxKey from "../Prefabs/InteractivObj/PasswordBox/PasswordBoxKey";
import FocusMoreParentObj from "../Prefabs/InteractivObj/Common/FocusMoreParentObj";
import TouYingObj from "../Prefabs/InteractivObj/TouYingObj/TouYingObj";
import PhysPassLock from "../Prefabs/InteractivObj/PhysPassLock/PhysPassLock";
import PhysPassKey from "../Prefabs/InteractivObj/PhysPassLock/PhysPassKey";
import MultiDimensionalInt from "../Prefabs/InteractivObj/PasswordBox/MultiDimensionalInt";

export default class LevelInit6 extends LevelInitBase{
    private room1:Laya.Sprite3D;
    private room2:Laya.Sprite3D;

    private container:Laya.Sprite3D;

    public startInitDetail(){
        this.levelRoot.addComponent(LevelControl6);
        this.room1 = this.LevelObjs.getChildByName("room1") as Laya.Sprite3D;
        this.room1.addComponent(RoomControl);
        this.room2 = this.LevelObjs.getChildByName("room2") as Laya.Sprite3D;
        this.room2.addComponent(RoomControl);
        this.container = this.room1.getChildByName("Container") as Laya.Sprite3D;

        let room1Walls =  this.room1.getChildByName("walls");
        let room2Walls =  this.room2.getChildByName("walls"); 

        //#region room1 wall1

        let wall1 = room1Walls.getChildByName("wall1");
        let shitiRoom = wall1.getChildByName("shitiRoom");

        let Box036 =  shitiRoom.getChildByName("Box036");
        let Box034 = Box036.getChildByName("Box034");
        let RotateObj_Box034 = utils.CommonUtils.CustomAddComponent(Box034,RotateObj) as RotateObj;
        RotateObj_Box034.rotateTime = 500;
        RotateObj_Box034.IsRotateOnce = true;
        RotateObj_Box034.targetRotate = new Laya.Vector3(0,0,0);
        RotateObj_Box034.VoiceName = "openGate";

        let Object022 = Box036.getChildByName("Object022");
        let MoveObj_Object022 =utils.CommonUtils.CustomAddComponent(Object022,MoveObj) as MoveObj;
        MoveObj_Object022.isConvertUnityPosition = true;
        MoveObj_Object022.targetPos = new Laya.Vector3(-0.017,-1.9,0.981);
        MoveObj_Object022.VoiceName = "move";
        MoveObj_Object022.tweenTime = 500;
        
        let SM_Prop_DeadBody_Laying_Female_002 = Object022.getChildByName("SM_Prop_DeadBody_Laying_Female_002");
        utils.CommonUtils.CustomAddComponent(SM_Prop_DeadBody_Laying_Female_002,FocusParentObj)

        let Box011 = SM_Prop_DeadBody_Laying_Female_002.getChildByName("Box011");
        let GamePropObj_Box011 = utils.CommonUtils.CustomAddComponent(Box011,GamePropObj) as GamePropObj;
        GamePropObj_Box011.gamePropId = 30;


        let Box037 = shitiRoom.getChildByName("Box037");

        let Box039 = Box037.getChildByName("Box039");
        let RotateObj_Box039 = utils.CommonUtils.CustomAddComponent(Box039,RotateObj) as RotateObj;
        RotateObj_Box039.rotateTime = 500;
        RotateObj_Box039.IsRotateOnce = true;
        RotateObj_Box039.targetRotate = new Laya.Vector3(0,0,0);
        RotateObj_Box039.VoiceName = "openGate";

        let Object023 = Box037.getChildByName("Object023");
        let MoveObj_Object023=utils.CommonUtils.CustomAddComponent(Object023,MoveObj) as MoveObj;
        MoveObj_Object023.isConvertUnityPosition = true;
        MoveObj_Object023.targetPos = new Laya.Vector3(-0.017,-1.918,0.981);
        MoveObj_Object023.VoiceName = "move";
        MoveObj_Object023.tweenTime = 500;

        let jinianpin = Object023.getChildByName("jinianpin");
        let GamePropObj_jinianpin = utils.CommonUtils.CustomAddComponent(jinianpin,GamePropObj) as GamePropObj;
        GamePropObj_jinianpin.gamePropId = 11;

        let Box038 = shitiRoom.getChildByName("Box038");

        let Box040 = Box038.getChildByName("Box040");
        let RotateObj_Box040 = utils.CommonUtils.CustomAddComponent(Box040,RotateObj) as RotateObj;
        RotateObj_Box040.rotateTime = 500;
        RotateObj_Box040.IsRotateOnce = true;
        RotateObj_Box040.targetRotate = new Laya.Vector3(0,0,0);
        RotateObj_Box040.VoiceName = "openGate";

        let Object024 = Box038.getChildByName("Object024");      
        let MoveObj_Object024=utils.CommonUtils.CustomAddComponent(Object024,MoveObj) as MoveObj;
        MoveObj_Object024.isConvertUnityPosition = true;
        MoveObj_Object024.targetPos = new Laya.Vector3(-0.02,-1.93,0.98);
        MoveObj_Object024.VoiceName = "move";
        MoveObj_Object024.tweenTime = 500;

        let SM_DeadBody_Female_018 =  Object024.getChildByName("SM_DeadBody_Female_018");    
        utils.CommonUtils.CustomAddComponent(SM_DeadBody_Female_018,FocusParentObj)


        let Object026 = wall1.getChildByName("Object026");
        utils.CommonUtils.CustomAddComponent(Object026,FocusParentObj);

        let longtou_famen =  Object026.getChildByName("longtou_famen");
        let RotateObj_longtou_famen = utils.CommonUtils.CustomAddComponent(longtou_famen,RotateObj) as RotateObj;
        RotateObj_longtou_famen.rotateTime = 500;
        RotateObj_longtou_famen.IsRotateOnce = true;
        // RotateObj_longtou_famen.isConvertUnityRotation = true;
        RotateObj_longtou_famen.targetRotate = new Laya.Vector3(0,0,90);
        RotateObj_longtou_famen.VoiceName = "lashuizha";
        RotateObj_longtou_famen.isNeedCallToLevel = true;

        let xishutai = Object026.getChildByName("xishutai");
        utils.CommonUtils.CustomAddComponent(xishutai,CallToLevel);

        let Plane001 =  Object026.getChildByName("Plane001");
        let MoveObj_Plane001 = utils.CommonUtils.CustomAddComponent(Plane001,MoveObj)as MoveObj;
        MoveObj_Plane001.isConvertUnityPosition = true;
        MoveObj_Plane001.targetPos = new Laya.Vector3(0.00654,0.026,0.486);
        MoveObj_Plane001.tweenTime = 500;

        let dead_touying001 = Object026.getChildByName("dead touying001");
        let GamePropObj_dead_touying001 = utils.CommonUtils.CustomAddComponent(dead_touying001,GamePropObj) as GamePropObj;
        GamePropObj_dead_touying001.gamePropId = 32;


        //#endregion

        //#region room1 wall2
        let wall2 = room1Walls.getChildByName("wall2");
        let door =  wall2.getChildByName("door");
        let RotateObj_door = utils.CommonUtils.CustomAddComponent(door,RotateObj) as RotateObj;
        RotateObj_door.rotateTime = 500;
        RotateObj_door.IsRotateOnce = true;
        // RotateObj_door.isConvertUnityRotation = true;
        RotateObj_door.targetRotate = new Laya.Vector3(0,0,-90);
        RotateObj_door.VoiceName = "openGate";
        RotateObj_door.isNeedCallToLevel = true;

        let darkGateCollider = wall2.getChildByName("darkGateCollider");
        utils.CommonUtils.CustomAddComponent(darkGateCollider,CallToLevel);

        let dead =  wall2.getChildByName("dead") as Laya.Sprite3D;
        (<Laya.MeshSprite3D>dead).meshRenderer.receiveShadow = true;
        (<Laya.MeshSprite3D>wall2).meshRenderer.receiveShadow = true;
        //#endregion

        //#region room1 wall3

        let wall3 = room1Walls.getChildByName("wall3");
        let Object010 = wall3.getChildByName("Object010");
        utils.CommonUtils.CustomAddComponent(Object010,FocusMoreParentObj)

        let famen = Object010.getChildByName("famen");
        let GamePropObj_famen = utils.CommonUtils.CustomAddComponent(famen,GamePropObj) as GamePropObj;
        GamePropObj_famen.gamePropId = 31;

        let jinianpin1 = wall3.getChildByName("jinianpin (1)");
        let GamePropObj_jinianpin1 = utils.CommonUtils.CustomAddComponent(jinianpin1,GamePropObj) as GamePropObj;
        GamePropObj_jinianpin1.gamePropId = 11;

        //#endregion

        //#region room1 wall4
        let wall4 = room1Walls.getChildByName("wall4") as Laya.MeshSprite3D;
        wall4.meshRenderer.castShadow = true;

        let room1EndGate = wall4.getChildByName("room1EndGate");
        let Gate_room1EndGate = utils.CommonUtils.CustomAddComponent(room1EndGate,Gate) as Gate;
        Gate_room1EndGate.needPropId = 111111111;
        Gate_room1EndGate.Axis = EnumData.Axis.X;
        Gate_room1EndGate.Angle = 130;

        let SM_Prop_Generator_01 = wall4.getChildByName("SM_Prop_Generator_01"); 
        utils.CommonUtils.CustomAddComponent(SM_Prop_Generator_01,FocusParentObj);

        let PasswordBox_SM_Prop_Generator_01 = utils.CommonUtils.CustomAddComponent(SM_Prop_Generator_01,PasswordBox) as PasswordBox;
        for (let index = 0; index < 12; index++) {
            PasswordBox_SM_Prop_Generator_01.correctIndex.push(1);
        }
        PasswordBox_SM_Prop_Generator_01.haveMoreCorrect = true;

        for (let index = 0; index < 13; index++) {
            PasswordBox_SM_Prop_Generator_01.correctIndexArray.push(new MultiDimensionalInt());
        }

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[0].intArray.push(1);
        PasswordBox_SM_Prop_Generator_01.correctIndexArray[0].intArray.push(3);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[1].intArray.push(0);
        PasswordBox_SM_Prop_Generator_01.correctIndexArray[1].intArray.push(2);
        
        PasswordBox_SM_Prop_Generator_01.correctIndexArray[2].intArray.push(1);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[3].intArray.push(0);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[4].intArray.push(1);
        PasswordBox_SM_Prop_Generator_01.correctIndexArray[4].intArray.push(3);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[5].intArray.push(1);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[6].intArray.push(0);
        PasswordBox_SM_Prop_Generator_01.correctIndexArray[6].intArray.push(2);
        
        PasswordBox_SM_Prop_Generator_01.correctIndexArray[7].intArray.push(1);
        PasswordBox_SM_Prop_Generator_01.correctIndexArray[7].intArray.push(3);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[8].intArray.push(1);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[9].intArray.push(2);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[10].intArray.push(1);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[11].intArray.push(1);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[12].intArray.push(1);
        PasswordBox_SM_Prop_Generator_01.correctIndexArray[12].intArray.push(3);

        PasswordBox_SM_Prop_Generator_01.correctIndexArray[12].intArray.push(0);

        let objs = SM_Prop_Generator_01.getChildByName("objs"); 
        
        for (let index = 1; index < 15; index++) {
            let name = "obj"+index;
            let obj = objs.getChildByName(name);
            let PasswordBoxKey_obj = utils.CommonUtils.CustomAddComponent(obj,PasswordBoxKey) as  PasswordBoxKey;
            PasswordBoxKey_obj.rotateAngle = 90;
            PasswordBoxKey_obj.isNoTween = true;
            PasswordBoxKey_obj.isX = true;
            PasswordBoxKey_obj.curRotateIndex = 0;
            if (index == 2 || index == 7 ) {
                PasswordBoxKey_obj.curRotateIndex = 1;
            }
        }

        let obj2Pos = objs.getChildByName("obj2Pos");
        utils.CommonUtils.CustomAddComponent(obj2Pos,CallToLevel);

        let obj7Pos = objs.getChildByName("obj7Pos");
        utils.CommonUtils.CustomAddComponent(obj7Pos,CallToLevel);

        //#endregion

        //#region room1Container
        let room1Container = this.room1.getChildByName("Container");
        let SM_Prop_Pillar_01 = room1Container.getChildByName("SM_Prop_Pillar_01") as Laya.MeshSprite3D;
        SM_Prop_Pillar_01.meshRenderer.castShadow = true;
        utils.CommonUtils.CustomAddComponent(SM_Prop_Pillar_01,FocusMoreParentObj);

        let touyingtai = SM_Prop_Pillar_01.getChildByName("touyingtai");
        utils.CommonUtils.CustomAddComponent(touyingtai,CallToLevel);

        let deadTouYing = SM_Prop_Pillar_01.getChildByName("deadTouYing");
        let dead_touying = deadTouYing.getChildByName("GameObject").getChildByName("dead touying") as Laya.Sprite3D;
        // console.log("castShadow", (<Laya.MeshSprite3D>dead_touying).meshRenderer.castShadow);
        (<Laya.MeshSprite3D>dead_touying).meshRenderer.castShadow = true;
       
        let TouYingObj_dead_touying = utils.CommonUtils.CustomAddComponent(dead_touying,TouYingObj);

        let Spot_Light:Laya.DirectionLight = deadTouYing.getChildByName("Spot Light") as Laya.DirectionLight;
        Spot_Light.shadowCascadesMode =Laya.ShadowCascadesMode.NoCascades;
        Spot_Light.shadowMode = Laya.ShadowMode.SoftHigh;
        Spot_Light.shadowDistance = 10;
		// Set shadow resolution.
        Spot_Light.shadowResolution = 1024;
        Spot_Light.shadowNormalBias = 4;
        console.log(Spot_Light);
        //#endregion

        //#region room2Wall1
        let room2Wall1 = room2Walls.getChildByName("wall1");
        let SM_Prop_Atm_01 = room2Wall1.getChildByName("SM_Prop_Atm_01");
        utils.CommonUtils.CustomAddComponent(SM_Prop_Atm_01,FocusParentObj);

        let PasswordBox_SM_Prop_Atm_01 = utils.CommonUtils.CustomAddComponent(SM_Prop_Atm_01,PasswordBox) as PasswordBox;
        PasswordBox_SM_Prop_Atm_01.correctIndex.push(2);
        PasswordBox_SM_Prop_Atm_01.correctIndex.push(1);
        PasswordBox_SM_Prop_Atm_01.correctIndex.push(3);
        PasswordBox_SM_Prop_Atm_01.correctIndex.push(0);
        PasswordBox_SM_Prop_Atm_01.haveMoreCorrect = false;

        let Cylinder012 =  SM_Prop_Atm_01.getChildByName("Cylinder011").getChildByName("Cylinder012");
        let PasswordBoxKey_Cylinder012 = utils.CommonUtils.CustomAddComponent(Cylinder012,PasswordBoxKey) as PasswordBoxKey;
        PasswordBoxKey_Cylinder012.rotateAngle = 90;
        PasswordBoxKey_Cylinder012.isNoTween = true;

        let Cylinder015 =  SM_Prop_Atm_01.getChildByName("Cylinder014").getChildByName("Cylinder015");
        let PasswordBoxKey_Cylinder015 = utils.CommonUtils.CustomAddComponent(Cylinder015,PasswordBoxKey) as PasswordBoxKey;
        PasswordBoxKey_Cylinder015.rotateAngle = 90;
        PasswordBoxKey_Cylinder015.isNoTween = true;

        let Cylinder017 =  SM_Prop_Atm_01.getChildByName("Cylinder016").getChildByName("Cylinder017");
        let PasswordBoxKey_Cylinder017 = utils.CommonUtils.CustomAddComponent(Cylinder017,PasswordBoxKey) as PasswordBoxKey;
        PasswordBoxKey_Cylinder017.rotateAngle = 90;
        PasswordBoxKey_Cylinder017.isNoTween = true;

        let Cylinder019 =  SM_Prop_Atm_01.getChildByName("Cylinder018").getChildByName("Cylinder019");
        let PasswordBoxKey_Cylinder019 = utils.CommonUtils.CustomAddComponent(Cylinder019,PasswordBoxKey) as PasswordBoxKey;
        PasswordBoxKey_Cylinder019.rotateAngle = 90;
        PasswordBoxKey_Cylinder019.isNoTween = true;

        let Box001 = SM_Prop_Atm_01.getChildByName("Box001");
        let RotateObj_Box001 = utils.CommonUtils.CustomAddComponent(Box001,RotateObj) as RotateObj;
        RotateObj_Box001.rotateTime = 500;
        RotateObj_Box001.IsRotateOnce = true;
        RotateObj_Box001.targetRotate = new Laya.Vector3(-120,0,0);
        RotateObj_Box001.VoiceName = "openGate";

        let GameObject = Box001.getChildByName("GameObject");
        utils.CommonUtils.CustomAddComponent(GameObject,CallToLevel);

        let Box017 = SM_Prop_Atm_01.getChildByName("Box017");
        let GamePropObj_Box017 = utils.CommonUtils.CustomAddComponent(Box017,GamePropObj) as GamePropObj;
        GamePropObj_Box017.gamePropId = 30;

        let hua = room2Wall1.getChildByName("hua");
        utils.CommonUtils.CustomAddComponent(hua,FocusParentObj);
        //#endregion

        //#region room2 wall3
        let room2Wall3 =  room2Walls.getChildByName("wall3");
        let ChamferBox001 =  room2Wall3.getChildByName("ChamferBox001");
        utils.CommonUtils.CustomAddComponent(ChamferBox001,FocusParentObj);

        let safeBox = ChamferBox001.getChildByName("safeBox");
        let RotateObj_safeBox = utils.CommonUtils.CustomAddComponent(safeBox,RotateObj) as RotateObj;
        RotateObj_safeBox.IsRotateOnce = true;
        // RotateObj_safeBox.isConvertUnityRotation = true;
        RotateObj_safeBox.rotateTime = 500;
        RotateObj_safeBox.VoiceName = "openGate";
        RotateObj_safeBox.targetRotate = new Laya.Vector3(0,0,90);

        let Object001 = safeBox.getChildByName("Object001");
        utils.CommonUtils.CustomAddComponent(Object001,CallToLevel);

        let physPassLock = safeBox.getChildByName("physPassLock");
        let PhysPassLock_physPassLock = utils.CommonUtils.CustomAddComponent(physPassLock,PhysPassLock) as PhysPassLock;
        PhysPassLock_physPassLock.correctPassInde.push(3);
        PhysPassLock_physPassLock.correctPassInde.push(2);
        PhysPassLock_physPassLock.correctPassInde.push(0);
        PhysPassLock_physPassLock.correctPassInde.push(7);

        for (let index = 0; index < physPassLock.numChildren; index++) {
            let passwordObj = physPassLock.getChildAt(index);
            let PhysPassKey_passwordObj = utils.CommonUtils.CustomAddComponent(passwordObj,PhysPassKey) as PhysPassKey;
            PhysPassKey_passwordObj.isRotateY = true;
            PhysPassKey_passwordObj.rotateAngle = -45;
        }

        let jinianpin2 = ChamferBox001.getChildByName("jinianpin");
        let GamePropObj_jinianpin2 = utils.CommonUtils.CustomAddComponent(jinianpin2,GamePropObj) as GamePropObj;
        GamePropObj_jinianpin2.gamePropId = 11;

        //#endregion

        //#region  room2 wall4
        let room2Wall4 = room2Walls.getChildByName("wall4");
        let darkGateRoom2 = room2Wall4.getChildByName("darkGateRoom2");
        utils.CommonUtils.CustomAddComponent(darkGateRoom2,CallToLevel);
        //#endregion
    }
}